<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">

          <a-col :md="6" :sm="8">
            <a-form-item label="桩编码">
              <a-input placeholder="请输入桩编码" v-model="queryParam.code"></a-input>
            </a-form-item>
          </a-col>
          <!--<a-col :md="6" :sm="8">-->
            <!--<a-form-item label="是否删除">-->
              <!--<a-input placeholder="请输入是否删除" v-model="queryParam.delFlag"></a-input>-->
            <!--</a-form-item>-->
          <!--</a-col>-->
        <template v-if="toggleSearchStatus">
        <a-col :md="6" :sm="8">
            <a-form-item label="桩编号">
              <a-input placeholder="请输入桩编号" v-model="queryParam.pileNumber"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="桩类型">
              <a-select
                style="width: 100%"
                placeholder="请输入桩类型"
                v-model="queryParam.pileType">
                <a-select-option value="1">直流</a-select-option>
                <a-select-option value="2" >交流</a-select-option>
              </a-select>
              <!--<a-input placeholder="请输入桩类型" v-model="queryParam.pileType"></a-input>-->
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="省">
              <!-- <a-input placeholder="请输入电价" v-model="queryParam.provinceId"></a-input>-->
              <a-select
                style="width: 100%"
                placeholder="请输入所属省"
                v-model="queryParam.provinceId">
                <a-select-option v-for="(province,provinceindex) in provinceList" :key="provinceindex.toString()" :value="province.id"  @click="queryCityList(province.id)">
                  {{ province.provinceName }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="市">
              <!-- <a-input placeholder="请输入市" v-model="queryParam.cityId"></a-input>-->
              <a-select
                style="width: 100%"
                placeholder="请输入所属市"
                v-model="queryParam.cityId">
                <a-select-option v-for="(city,cityindex) in cityList" :key="cityindex.toString()" :value="city.id" @click="queryDistrictList(city.id)">
                  {{ city.cityName }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="区">
              <!-- <a-input placeholder="请输入区" v-model="queryParam.districtId"></a-input>-->
              <a-select
                style="width: 100%"
                placeholder="请输入所属区"
                v-model="queryParam.districtId">
                <a-select-option v-for="(district,districtindex) in districtList" :key="districtindex.toString()" :value="district.id" @click="siteListByDistrict(district.id)">
                  {{ district.districtName }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="8">
            <a-form-item label="充电站">
              <a-select
                style="width: 100%"
                placeholder="请选择充电站"
                v-model="queryParam.siteId">
               <!-- v-decorator="[ 'siteId', {rules: [{ required: true, message: '请选择充电站' }]}]">-->
                <a-select-option v-for="(siteId,siteIdindex) in siteList" :key="siteIdindex.toString()" :value="siteId.id">
                  {{ siteId.siteName }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <!--<a-form-item-->
            <!--:labelCol="labelCol"-->
            <!--:wrapperCol="wrapperCol"-->
            <!--label="充电站">-->
            <!--&lt;!&ndash;<a-input placeholder="请选择充电站" v-decorator="['siteId', validatorRules.siteId]" />&ndash;&gt;-->
            <!--<a-select-->
              <!--style="width: 100%"-->
              <!--placeholder="请选择充电站"-->
              <!--v-decorator="[ 'siteId', {rules: [{ required: true, message: '请选择充电站' }]}]">-->
              <!--<a-select-option v-for="(siteId,siteIdindex) in siteList" :key="siteIdindex.toString()" :value="siteId.id">-->
                <!--{{ siteId.siteName }}-->
              <!--</a-select-option>-->
            <!--</a-select>-->
          <!--</a-form-item>-->
        </template>
          <a-col :md="6" :sm="8" >
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('充电桩管理')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <wxcChargingPile-modal ref="modalForm" @ok="modalFormOk"></wxcChargingPile-modal>
  </a-card>
</template>

<script>
  import WxcChargingPileModal from './modules/WxcChargingPileModal'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { postAction } from '@/api/manage'
  export default {
    name: "WxcChargingPileList",
    mixins:[JeecgListMixin],
    components: {
      WxcChargingPileModal
    },
    data () {
      return {
        description: '充电桩管理页面',
        provinceList:[],
        cityList:[],
        districtList:[],
        siteList:[],
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
           },
		   {
            title: '桩编码',
            align:"center",
            dataIndex: 'code'
           },
		   // {
       //      title: '是否删除',
       //      align:"center",
       //      dataIndex: 'delFlag'
       //     },
		   {
            title: '桩编号',
            align:"center",
            dataIndex: 'pileNumber'
           },
		   {
            title: '桩类型',
            align:"center",
            dataIndex: 'pileType'
           },
		   {
            title: '充电站',
            align:"center",
            dataIndex: 'siteId'
           },
		   {
            title: '运行状态',
            align:"center",
            dataIndex: 'status'
           },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],
		url: {
          list: "/wxcchargingpile/wxcChargingPile/list",
          delete: "/wxcchargingpile/wxcChargingPile/delete",
          deleteBatch: "/wxcchargingpile/wxcChargingPile/deleteBatch",
          exportXlsUrl: "wxcchargingpile/wxcChargingPile/exportXls",
          importExcelUrl: "wxcchargingpile/wxcChargingPile/importExcel",
          provinceListUrl:"/dictionary/dictionary/provinceList",
          cityListUrl:"/dictionary/dictionary/cityList",
          districtListUrl:"/dictionary/dictionary/districtList",
          siteListUrl:"/wxcchargingsite/wxcChargingSite/siteListByDistrict",
       },
    }
  },
  computed: {
    importExcelUrl: function(){
      this.queryProvinceList();
      this.queryCityList();
      this.queryDistrictList();
      this.siteListByDistrict();
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
    methods: {
      queryProvinceList(){
        postAction(this.url.provinceListUrl).then((res)=>{
          if(res.success){
            this.provinceList = res.result;
          }else{
            console.log(res.message);
          }
        }).catch((err) => {
          this.$message.error("请求异常："+err)
        })
      },
      queryCityList(provinceId){
        let params = {provinceId:provinceId}
        postAction(this.url.cityListUrl,params).then((res)=>{
          if(res.success){
            this.cityList = res.result;
          }else{
            console.log(res.message);
          }
        }).catch((err) => {
          this.$message.error("请求异常："+err)
        })
      },
      queryDistrictList(cityId){
        let params = {cityId:cityId}
        postAction(this.url.districtListUrl,params).then((res)=>{
          if(res.success){
            this.districtList = res.result;
          }else{
            console.log(res.message);
          }
        }).catch((err) => {
          this.$message.error("请求异常："+err)
        })
      },
      siteListByDistrict(districtId){
        let params = {districtId:districtId}
        postAction(this.url.siteListUrl,params).then((res)=>{
          if(res.success){
            this.siteList = res.result;
          }else{
            console.log(res.message);
          }
        }).catch((err)=>{
          this.$message.error("请求异常："+err)
        })

      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>